package zhishu.iceyyy.com.bxq_2500.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import zhishu.iceyyy.com.bxq_2500.R;
import zhishu.iceyyy.com.bxq_2500.activity.SouSuoActivity;
import zhishu.iceyyy.com.bxq_2500.adapter.SynBuy_CGS_FragmentAdapter;
import zhishu.iceyyy.com.bxq_2500.base.ALL_CONFIG;
import zhishu.iceyyy.com.bxq_2500.test.Movie_Fragment;

/**
 * A simple {@link Fragment} subclass.
 */
public class OneFragment extends Fragment {

    View view;
    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.image)
    ImageView image;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (view == null) {
            view = View.inflate(getActivity(), R.layout.fragment_blank1, null);
            ButterKnife.bind(this, view);
            initview();
            image.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    startActivity(new Intent(getActivity(), SouSuoActivity.class));
                }
            });

        }
        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null) {
            parent.removeView(view);
        }


        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();


    }

    List<Fragment> ccList = new ArrayList<Fragment>();

    void initview() {
        if (ALL_CONFIG.dataBeans != null && ALL_CONFIG.dataBeans.size() > 0) {
            for (int i = 0; i < ALL_CONFIG.dataBeans.size(); i++) {

                ccList.add(Movie_Fragment.newInstance("" + ALL_CONFIG.dataBeans.get(i).getType_id()));

                SynBuy_CGS_FragmentAdapter adapter = new SynBuy_CGS_FragmentAdapter(getActivity().getSupportFragmentManager(), ccList);
                viewpager.setOffscreenPageLimit(1);
                viewpager.setAdapter(adapter);
                tabs.setTabMode(TabLayout.MODE_FIXED);
                tabs.setupWithViewPager(viewpager);// 将vi

            }
        } else {
            Toast.makeText(getActivity(), "网络错误", Toast.LENGTH_SHORT).show();
        }


    }
}
